package com.itajk.calculationtest;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.VideoView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class radioReward extends AppCompatActivity {

    Button start_button;
    Button stop_button;
    Button back_to_face_button;
    VideoView videoView;
    MediaController mediaController;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.radio_reward);

        start_button = findViewById(R.id.button);
        stop_button = findViewById(R.id.button11);
        back_to_face_button = findViewById(R.id.button12);
        videoView = new VideoView(this);
        videoView = findViewById(R.id.videoView);
        mediaController = new MediaController(this);

        start_button.setOnClickListener(new radioClick());
        stop_button.setOnClickListener(new radioClick());

        back_to_face_button.setOnClickListener(new View.OnClickListener() {
            @Override
            //从视频奖励页面跳转到主界面
            public void onClick(View v) {
                Intent back_to_face = new Intent(radioReward.this,MainActivity.class);
                startActivity(back_to_face);
            }
        });
    }

    class radioClick implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            /*String uri = "android.resource://" + getPackageName() + "/" + R.raw.muscle3;*/
            String uri = "android.resource://" + getPackageName() + "/" + R.raw.muscle3;
            videoView.setVideoURI(Uri.parse(uri));
            mediaController.setMediaPlayer(videoView);

            videoView.setMediaController(mediaController);
            videoView.requestFocus();
            if (v == start_button) {
                videoView.start();
            } else if (v == stop_button) {
                videoView.stopPlayback();
            }
        }
    }


}
